package systemweb

import (
	"go-middle/app/admin/service/adminservice"
	"go-middle/app/common/model/admin"
	"go-middle/app/common/model/menu"
	"go-middle/app/common/model/role"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
)

//Info 系统信息
func Info(r *ghttp.Request) {
	r.Response.WriteTpl("admin/system/info.html")
}

//Menu 菜单列表
func Menu(r *ghttp.Request) {
	r.Response.WriteTpl("admin/system/menu.html")
}

//MenuEdit 编辑菜单
func MenuEdit(r *ghttp.Request) {
	id := r.GetInt64("id", 0)
	if id > 0 {
		//编辑页面
		data := adminservice.GetMenuByID(id)
		r.GetView().Assign("info", data)
		r.GetView().Assign("info_route", adminservice.EncodeAdminRoute(data.Method, data.Href))
	} else {
		//添加页面
		r.GetView().Assign("info", &menu.Entity{})
		r.GetView().Assign("info_route", "")
	}
	list := adminservice.GetPermissionTreeSelect()
	r.Response.WriteTpl("admin/system/menu_edit.html", g.Map{
		"menu_list": list,
		"route":     adminservice.GetAdminRouteMap(),
	})
}

//Admin 用户列表
func Admin(r *ghttp.Request) {
	r.Response.WriteTpl("admin/system/admin.html")
}

//AdminEdit 编辑用户
func AdminEdit(r *ghttp.Request) {
	id := r.GetInt64("id", 0)
	if id > 0 {
		//编辑页面
		data := adminservice.GetAdminById(id)
		r.GetView().Assign("info", data)
		if data.Roles != "" {
			r.GetView().Assign("role", role.GetName(data.Roles))
		}
	} else {
		//添加页面
		r.GetView().Assign("info", &admin.Entity{})
		r.GetView().Assign("role", "")
	}
	r.Response.WriteTpl("admin/system/admin_edit.html")
}

//Role 角色列表
func Role(r *ghttp.Request) {
	r.Response.WriteTpl("admin/system/role.html")
}

//Permission 权限树
func Permission(r *ghttp.Request) {
	r.GetView().Assign("role_id", r.GetInt("role_id", 0))
	r.Response.WriteTpl("admin/system/permission.html")
}
